import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
  UseInterceptors
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { YixiantongService } from 'src/yixiantong/yixiantong.service';
import { YixiantongFieldsGoods } from 'src/entities/yixiantong-fields-goods';
import { AuthInterceptor } from 'src/base/auth-interceptor';
import { YixiantongGoodsListSearchDto } from './yixiantong-goods.dto';
import { YixiantongGoodsService } from './yixiantong-goods.service';

@ApiTags('一线通 - 【类目管理】')
@Controller('/api/yixiantong-goods')
@UseInterceptors(new AuthInterceptor())
export class YixiantongGoodsController {
  constructor(
    public readonly yixiantongService: YixiantongService,
    public readonly yixiantongGoodsService: YixiantongGoodsService,
  ) {}

  @Get('/list')
  @ApiOperation({ summary: '获取类目分页列表' })
  public async getList(@Query() searchParams: Partial<YixiantongGoodsListSearchDto>) {
    return this.yixiantongGoodsService.getList(searchParams);
  }

  @Get('/:id')
  @ApiOperation({ summary: '获取类目详情' })
  public async getListDetail(@Param('id') id: string) {
    return this.yixiantongService.getDetail(id);
  }

  @Post('/')
  @ApiOperation({ summary: '新增类目' })
  public async addListItem(@Body() params: YixiantongFieldsGoods) {
    return await this.yixiantongGoodsService.addListItem(params);
  }

  @Put('/:id')
  @ApiOperation({ summary: '更新类目' })
  public async updateListItem(@Param('id') id: string, @Body() params: YixiantongFieldsGoods) {
    return await this.yixiantongGoodsService.updateListItem(id, params);
  }

  @Delete('/:id')
  @ApiOperation({ summary: '删除类目' })
  public async deleteListItem(@Param('id') id: string) {
    return await this.yixiantongGoodsService.deleteListItem(id);
  }
}
